#pragma once

/*
struct eqedge
{
  bool operator()(const figureEdge e1, const figureEdge e2) const
  {
    return (e1 == e2);
  }
};
*/


//This contains the pair edge -> vertex
//At the beggining edge -> shows to the edge end point
typedef std::map<figureEdge,figureVertice, std::less<std::vector<figureEdge>::value_type> >  edgeMapHelper;
//typedef std::hash_map<figureEdge,figureVertice,hash<figureEdge>,eqedge> edgeMap;
typedef std::pair<figureEdge,figureVertice> edgePair;
typedef edgeMapHelper::iterator             edgeMapIter;

//The list of vertices
//The vertices are added in runtime 
//typedef std::list<figureVertice> verticeList;
//typedef verticeList::iterator    verticeIterator;

//The list of added edges
//All operations will be done on this list, like add, remove
//typedef std::list<figureEdge> edgeList;
//typedef edgeList::iterator    edgeIterator;

//The queue contains all edges on the left from vertice ordered by x coordinate
//where max(x) has a highest priority
typedef std::priority_queue<figureEdge,std::vector<figureEdge>, std::greater<std::vector<figureEdge>::value_type> > edgeLeft;

//The queue contains all edges on the right from vertice ordered by x coordinate
//where min(x) has a highest priority
typedef std::priority_queue<figureEdge,std::vector<figureEdge>, std::less<std::vector<figureEdge>::value_type> > edgeRight;

//The set of ordered vertices based on lenght between given point
//and found vertice
typedef SearchTree<figureEdge> binaryTree;
typedef binaryTree::iterator   binaryTreeIterator;




class Helper
{
protected:
  figureVertice   m_helper;
  binaryTree   *  m_binTree;
  edgeMapHelper * m_edgeMap;

  bool            m_helperExist;

  LinearFunction  m_linear;
  Vector2D        m_vector;
  figureEdge      m_currEdge;
  
public:
  Helper(void);
  ~Helper(void);
  void Init();//should we put there a list of edges
  //void RemoveEdge(const figureEdge &);
  void InsertEdge(const figureEdge &, const figureVertice &);
  void UpdateEgde(const figureEdge &, const figureVertice &);
  void UpdateCurrEgde(const figureVertice &);
  //void InsertVertice(const figureVertice &);
  //void RemoveVertice(figureVertice &);
  figureVertice & FindVertice(const figureVertice &);
  figureVertice & GetHelper(const figureEdge &);
  bool  IsFound();

  void AddEdgeBT(const figureEdge &);
  void DelEdgeBT(const figureEdge &);

protected:  
  void OrderEdges(const figureVertice &);
  void CleanQueues();

#ifdef DEBUG
  void  TestMap();
#endif
};
